package com.trantor.stockmarketwatch;

import org.xml.sax.Attributes;
import org.xml.sax.SAXException;
import org.xml.sax.helpers.DefaultHandler;

public class GoogleStockEntryHandler extends DefaultHandler {
	
	private StockEntry stockEntry = new StockEntry();

	@Override
	public void startElement(String uri, String localName, String qName,
			Attributes attributes) throws SAXException {
		if (localName.equals("symbol")) {
			stockEntry.setTicker(attributes.getValue("data"));
		} else
		if (localName.equals("last")) {
			stockEntry.setPrice(attributes.getValue("data"));
		} else
		if (localName.equals("change")) {
			stockEntry.setChange(attributes.getValue("data"));
		} else
		if (localName.equals("perc_change")) {
			stockEntry.setPercent_change(attributes.getValue("data"));
		}
	}

	@Override
	public void endElement(String uri, String localName, String qName)
			throws SAXException {
		// TODO Auto-generated method stub
		super.endElement(uri, localName, qName);
	}

	public StockEntry getStockEntry() {
		return stockEntry;
	}
}
